﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;

#endregion


namespace ScrumTable.Common.Net
{
    /// <summary>
    /// This class wraps information about an additional service instance.
    /// </summary>
    public class ServiceRegistration
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        /// <summary>
        /// Gets a new empty service registration.
        /// </summary>
        public static readonly ServiceRegistration Empty = new ServiceRegistration();

        private readonly bool _hasServiceUrl = true;

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        /// <summary>
        /// Gets the portal uri.
        /// </summary>
        /// <remarks>Returns the retrieved server url or a null reference.</remarks>
        public Uri PortalUri
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets the service uri.
        /// </summary>
        /// <remarks>Returns the retrieved server url or a null reference.</remarks>
        public Uri ServiceUri
        {
            get;
            private set;
        }

        /// <summary>
        /// Returns true if the uris are available.
        /// </summary>
        public bool HasServiceUri
        {
            get { return _hasServiceUrl; }
        }

        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        /// <summary>
        /// Creates a new ServiceRegistration instance.
        /// </summary>
        public ServiceRegistration(string portalUri, string serviceUri = null)
        {
            PreCondition.AssertNotNull(portalUri, "portalUri");

            PortalUri = new Uri(portalUri, UriKind.RelativeOrAbsolute);
            ServiceUri = (serviceUri != null) ? new Uri(serviceUri, UriKind.RelativeOrAbsolute) : null;
        }

        /// <summary>
        /// Creates a new ServiceRegistration instance.
        /// </summary>
        public ServiceRegistration(
            Uri portalUri,
            Uri serviceUri = null)
        {
            PreCondition.AssertNotNull(portalUri, "portalUri");

            PortalUri = portalUri;
            ServiceUri = (serviceUri ?? portalUri);
        }

        /// <summary>
        /// Creates a new ServiceRegistration instance.
        /// </summary>
        private ServiceRegistration()
        {
            PortalUri = UriUtil.Empty;
            ServiceUri = UriUtil.Empty;

            _hasServiceUrl = false;
        }

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            return PortalUri.ToString();
        }

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        #endregion
    }
}